package com.caojing.haolemai.ui.outlets.outletsSharefragment;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.caojing.haolemai.bean.OutletsSharefragmentBean;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/10/18 0018.
 */
public class OutletsShareFragmentPresenter implements OutletsShareFragmentContract.Presenter {
    private OutletsShareFragmentContract.View view;
    private OutletsShareFragmentContract.Modle modle;

    public OutletsShareFragmentPresenter(OutletsShareFragmentContract.View view) {
        this.view = view;
        this.modle = new OutletsShareFragmentModle();
    }

    @Override
    public void getVertical(String pager, Map<String, String> params) {
        modle.getVertical(pager, params, new Callback<OutletsSharefragmentBean>() {
            @Override
            public void onResponse(Call<OutletsSharefragmentBean> call, Response<OutletsSharefragmentBean> response) {
                final OutletsSharefragmentBean outletsSharefragmentBean = response.body();
                if (outletsSharefragmentBean != null) {
                    Handler handler = new Handler(Looper.getMainLooper());
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            view.onGetVerticalSucess(outletsSharefragmentBean);
                        }
                    });
                }

            }

            @Override
            public void onFailure(Call<OutletsSharefragmentBean> call, Throwable t) {
                Log.i("TAG", t.getMessage());
                view.onGetVerticalFail("网络连接失败");
            }
        });


    }
}
